package group2assignone.ucm.manager;

import group2assignone.dao.MyDAO;
import group2assignone.model.Flight;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.manager.DeleteFlightView;

/**
 * Use Case: Delete Flight Search                                           <br>
 * Pre-condition: Manager has clicked search from delete flight view.       <br>
 * Post-condition: UI is updated.                                           <br>
 * 1. System retrieves flight number of flight to delete.                   <br>
 * 2. System retrieves flight details.                                      <br>
 * 3. System updates UI to display flight details.                          <br>
 *                                                                          <br>
 * 2.a. - Flight does not exist.                                            <br>
 *      - System resets UI input fields.                                    <br>
 *      - System displays error message.                                    <br>
 * @author group2                                                           <br>
 */
public class UCDeleteFlightSearch implements UCController {

    private DeleteFlightView deleteView = new DeleteFlightView();
    private Flight f = new Flight();

    /**
     * sets view and flight
     * @param dView
     * @param fl
     */
    public UCDeleteFlightSearch(DeleteFlightView dView, Flight fl) {
        deleteView = dView;
        f = fl;
    }
/**
 * use case to search for flight to delete.
 */
    @Override
    public void run() {
        //1. System retrieves flight number of flight to delete.
        //2. System retrieves flight details.
        MyDAO coms = UCStartup.getInstance().getDAO();
        f = coms.sQLGetFlight(deleteView.getFlightNum());

        if (f.getFlightNum().equals(null)) //if flight doesn't exist
        { //2.a. - Flight does not exist.
          // - System resets UI input fields.
            deleteView.resetFlightNum();
          // - System displays error message.
            deleteView.errorFlightNum();
        } else {//3. System updates UI to display flight details.
            deleteView.showFlightDetails(f);
        }
    }
}
